package com.katze.boot.common.runner;

import com.katze.common.env.AppEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Order
@Component
public class StartedUpRunner implements ApplicationRunner {
    private static final Logger log = LoggerFactory.getLogger(StartedUpRunner.class);

    @Autowired
    private ConfigurableApplicationContext context;

    @Override
    public void run(ApplicationArguments args) {
        if (context.isActive()) {
            log.info(" __    ___   _      ___   _     ____ _____  ____ ");
            log.info("/ /`  / / \\ | |\\/| | |_) | |   | |_   | |  | |_  ");
            log.info("\\_\\_, \\_\\_/ |_|  | |_|   |_|__ |_|__  |_|  |_|__ ");
            log.info("                                                      ");
            log.info("APP 启动完毕, 程序名称: '{}' (程序入口类: {}, 版本号: {}), 工作目录: {} , PID: {}, Tomcat基础目录: {}, Tomcat公共目录: {}, 时间: {}",
                    AppEnvironment.APP_NAME.getValue(),
                    AppEnvironment.MAIN_CLASS.getValue(),
                    AppEnvironment.APP_VERSION.getValue(),
                    AppEnvironment.APP_HOME.getValue(),
                    AppEnvironment.PID.getValue(),
                    AppEnvironment.TOMCAT_BASE_DIR.getValue(),
                    AppEnvironment.TOMCAT_DOC_BASE.getValue(),
                    LocalDateTime.now());
        }
    }
}
